package com.liy.framework.common.mybatis.config;

import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
@AutoConfigureAfter({MybatisConfiguration.class})
public class MapperScannerConfig implements EnvironmentAware {

    private String basePackage;

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
        mapperScannerConfigurer.setBasePackage(this.basePackage);
        return mapperScannerConfigurer;
    }

    public void setEnvironment(Environment environment) {
        this.basePackage = environment.getProperty("mybatis.basepackage");
    }
}
